package com.software.seakdream.application.worker;



import com.software.seakdream.domain.recommend.SimilarAudios;
import com.software.seakdream.entity.UserInfo;
import com.software.seakdream.service.UserInfoService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import java.util.Date;
import java.util.List;


@Component
public class UserXxlJob {

    private Logger logger = LoggerFactory.getLogger(UserXxlJob.class);
    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private SimilarAudios similarAudios;


    @XxlJob("vipStateJobHandler")
    public void vipStateJobHandler() throws Exception {
        logger.info("Vip过期扫描 Begin");

        List<UserInfo> allUser = userInfoService.queryAllUser();
        for (UserInfo user:allUser){
            if (user.getIfVip().equals("1") && user.getVipEndTime().before(new Date())){
                userInfoService.updateIfVip(user.getUserId(),"2");
                System.out.println("用户"+user.getUserId()+"vip已经过期");
            }
        }
        logger.info("Vip过期扫描 End");

    }

    @XxlJob("dailyAudiosJobHandler")
    public void dailyAudiosJobHandler() throws Exception {
        logger.info("每日推荐刷新 Begin");

        similarAudios.setDailyAudio();

        logger.info("每日推荐刷新 End");

    }


}

